home *** CD-ROM | disk | FTP | other *** search
/ Fritz: All Fritz / All Fritz.zip / All Fritz / FILES / PROGNG_C / TPTC17GS.LZH / TPCMISC.INC < prev    next >
Text File  |  1988-04-07  |  5KB  |  240 lines

  1.  
  2. (*
  3.  * TPTC - Turbo Pascal to C translator
  4.  *
  5.  * (C) 1988 Samuel H. Smith (rev. 13-Feb-88)
  6.  *
  7.  *)
  8.  
  9.  
  10. (********************************************************************)
  11. procedure mark_time(var long: longint);
  12.    {report time in clock ticks since midnight}
  13. var
  14.    words:   record
  15.                l,h: word;
  16.             end   absolute long;
  17.    reg:     registers;
  18.    
  19. begin
  20.    reg.ah := 0;  {get time of day}
  21.    intr($1a,reg);
  22.    words.l := reg.dx;
  23.    words.h := reg.cx;
  24. end;
  25.  
  26.  
  27. (********************************************************************)
  28. procedure abortcheck;
  29.    {check for the abort(escape) key}
  30. var
  31.    c:  char;
  32. begin
  33.    if keypressed then
  34.    begin
  35.       c := readkey;
  36.       if c = #27 then
  37.          fatal('Aborted by <escape> key');
  38.    end;
  39. end;
  40.  
  41.  
  42. (********************************************************************)
  43. procedure puttok;
  44.    {output the current token and a space to the output}
  45. begin
  46.    write(ofd[unitlevel],ltok,' ');
  47.    linestart := false;
  48. end;
  49.  
  50.  
  51. (********************************************************************)
  52. procedure putline;
  53.    {start a new line in the output file}
  54. begin
  55.    writeln(ofd[unitlevel]);
  56.    inc(objtotal);
  57.    linestart := true;
  58. end;
  59.  
  60.  
  61. (********************************************************************)
  62. procedure closing_statistics;
  63. var
  64.    secs: real;
  65.    rate: real;
  66.  
  67. begin
  68.  
  69.    {terminate any active output files}
  70.    if in_interface then
  71.       pimplementation;
  72.    purgetable(locals,nil);
  73.    while unitlevel > 0 do
  74.       exit_procdef;
  75.    putline;
  76.    putline;
  77.    purgetable(globals,nil);
  78.    close(ofd[unitlevel]);
  79.  
  80.    {determine statistics}
  81.    mark_time(curtime);
  82.    secs := int(curtime-starttime) / ticks_per_second;
  83.  
  84.    rate := int(srctotal) / secs * 60.0;
  85.    {rate := int(objtotal) / secs * 60.0;}
  86.    
  87.    {last status display on main file}
  88.    if debug then 
  89.       writeln
  90.    else
  91.    if not redirect then
  92.       write(^M);
  93.    writeln(srcfiles[srclevel],'(',srclines[srclevel],')');
  94.  
  95.    {report statistics}
  96.    writeln(srctotal,' source lines, ',
  97.            objtotal,' object lines, ',
  98.            secs:0:1,' seconds, ',
  99.            rate:0:0,' lines/min.');
  100. end;
  101.  
  102.  
  103. (********************************************************************)
  104. procedure error_message (message:       string);
  105.    {place an error message into the object file and on the screen}
  106. var
  107.    msg: string;
  108.    
  109. begin
  110.    msg := srcfiles[srclevel]+
  111.           '('+itoa(srclines[srclevel])+'): '+ 
  112.           message+', tok='+ ltok;
  113.            
  114.    if debug then 
  115.       writeln
  116.    else 
  117.    if not redirect then
  118.       write(^M);
  119.    writeln(output,msg);
  120.  
  121.    putline;
  122.    writeln(ofd[unitlevel],'/* TPTC: ',msg,' */');
  123.    write(ofd[unitlevel],spaces);
  124.    inc(objtotal);
  125. end;
  126.  
  127.  
  128. (********************************************************************)
  129. procedure comment_statement;
  130. begin
  131.    puts(' /* ');
  132.  
  133.    repeat
  134.       puttok;
  135.       gettok;
  136.    until (tok[1] = ';');
  137.  
  138.    puts(' */ ');
  139. end;
  140.  
  141.  
  142. (********************************************************************)
  143. procedure warning (message:       string);
  144.    {report a warning message unless warnings are disabled}
  145. begin
  146.    if not quietmode then
  147.       error_message('Warning: '+message);
  148. end;
  149.  
  150.  
  151. (********************************************************************)
  152. procedure syntax (message:       string);
  153.    {report a syntax error and skip to the next ';'}
  154. begin
  155.    if (not recovery) or (not quietmode) then
  156.       error_message('Error: '+message);
  157.    gettok;
  158.    recovery := true;
  159. end;
  160.  
  161.  
  162. (********************************************************************)
  163. procedure fatal (message:       string);
  164.    {abort translation with a fatal error}
  165. begin
  166.    error_message('Fatal: '+message);
  167.    closing_statistics;
  168.    halt(88);
  169. end;
  170.  
  171.  
  172. (********************************************************************)
  173. procedure puts(s: string);
  174.    {output a string the output file}
  175. begin
  176.    write(ofd[unitlevel],s);
  177.    if s[1] = ^J then
  178.    begin
  179.       inc(objtotal);
  180.       linestart := true;
  181.    end
  182.    else
  183.       linestart := false;
  184. end;
  185.  
  186.  
  187. (********************************************************************)
  188. procedure putln(s: string);
  189.    {output a string the output file and newline}
  190. begin
  191.    puts(s);
  192.    putline;
  193. end;
  194.  
  195.  
  196. (********************************************************************)
  197. procedure newline;
  198.    {start a new line in the output file;  indent to the same level
  199.     as the current line}
  200. begin
  201.    putline;
  202.    write(ofd[unitlevel],spaces);
  203. end;
  204.  
  205.  
  206. (********************************************************************)
  207. procedure usesemi;
  208.    {consume a semicolon}
  209. begin
  210.    if tok[1] = ';' then
  211.       gettok;
  212. end;
  213.  
  214.  
  215. (********************************************************************)
  216. procedure psemi;
  217.    {produce and consume a semicolon}
  218. begin
  219.    if tok[1] = ';' then
  220.    begin
  221.       puttok;
  222.       gettok;
  223.    end;
  224. end;
  225.  
  226. (********************************************************************)
  227. procedure forcesemi;
  228.    {force a semicolon}
  229. begin
  230.    if tok[1] = ';' then
  231.       psemi
  232.    else
  233.  
  234.    begin
  235.       puts(';');
  236.       newline;
  237.    end;
  238. end;
  239.  
  240.